<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Subversion</title>
<link rel="stylesheet" type="text/css" href="../C.css">
<script type="text/javascript" src="../jquery.js"></script><script type="text/javascript" src="../jquery.syntax.js"></script><script type="text/javascript" src="../yelp.js"></script>
</head>
<body id="home">
<!--<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript">
        _uacct = "UA-1018242-8";
        urchinTracker();
      </script><script>
      function englishPageVersion() {
        var href = window.location.href;
        if (href.slice(-1) == "/") {
                window.location = "index.html.en";
        } else {
                window.location = href.replace(/\.html.*/, ".html.en");
        }
         return false;
      }
      function browserPreferredLanguage() {
        var href = window.location.href;
        if (href.slice(-1) == "/") {
                window.location = href;
        } else {
                window.location = href.replace(/\.html.*/, ".html");
        }
        return false;
      }
      </script>--><div id="container">
<div id="container-inner">
<div id="mothership"><ul>
<li><a href="https://partners.ubuntu.com">Partners</a></li>
<li><a href="https://www.ubuntu.com/support/community-support">Support</a></li>
<li><a href="https://community.ubuntu.com">Community</a></li>
<li><a href="https://www.ubuntu.com">Ubuntu.com</a></li>
</ul></div>
<div id="header">
<h1 id="ubuntu-header"><a href="https://help.ubuntu.com/">Ubuntu Documentation</a></h1>
<ul id="main-menu">
<li><a class="main-menu-item current" href="https://help.ubuntu.com/">Official Documentation</a></li>
<li><a href="https://help.ubuntu.com/community/CommunityHelpWiki">Community Help Wiki</a></li>
<li><a href="https://community.ubuntu.com/t/contribute/26">Contribute</a></li>
</ul>
</div>
<div id="menu-search"><div id="search-box">
<noscript><form action="https://www.google.com/cse" id="cse-search-box"><div>
<input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq"><input type="hidden" name="ie" value="UTF-8"><input type="text" name="q" size="21"><input type="submit" name="sa" value="Search">
</div></form></noscript><!--
<script>
                document.write('<form action="https://help.ubuntu.com/search.html" id="cse-search-box">');
                document.write('  <div>');
                document.write('    <input type="hidden" name="cof" value="FORID:9">');
                document.write('    <input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq">');
                document.write('    <input type="hidden" name="ie" value="UTF-8">');
                document.write('    <input type="text" name="q" size="21">');
                document.write('    <input type="submit" name="sa" value="Search">');
                document.write('  </div>');
                document.write('</form>');
              </script>-->
</div></div>
<div class="trails"><div class="trail">
<a href="https://help.ubuntu.com/18.04" class="trail">Ubuntu 18.04</a> » <a class="trail" href="../index.html" title="Ubuntu Server Guide">Ubuntu Server Guide</a> » <a class="trail" href="version-control-system.html" title="Version Control System">Version Control System</a> » </div></div>
<div id="cwt-content" class="clearfix content-area"><div id="page">
<div id="content">
<div class="links nextlinks">
<a class="nextlinks-prev" href="git.html" title="Git">Previous</a><a class="nextlinks-next" href="version-control-ref.html" title="References">Next</a>
</div>
<div class="hgroup"><h1 class="title">Subversion</h1></div>
<div class="region">
<div class="contents"><p class="para">
Subversion is an open source version control system. Using Subversion, you can record the history of source files and documents. It manages files and directories over time. A tree of files is placed into a central repository. The repository is much like an ordinary file server, except that it remembers every change ever made to files and directories.
          </p></div>
<div class="links sectionlinks" role="navigation"><ul>
<li class="links"><a class="xref" href="subversion.html#subversion-installation" title="Installation">Installation</a></li>
<li class="links"><a class="xref" href="subversion.html#subversion-configuration" title="Server Configuration">Server Configuration</a></li>
<li class="links"><a class="xref" href="subversion.html#access-methods" title="Access Methods">Access Methods</a></li>
</ul></div>
<div class="sect2 sect" id="subversion-installation"><div class="inner">
<div class="hgroup"><h2 class="title">Installation</h2></div>
<div class="region"><div class="contents">
<p class="para">
To access Subversion repository using the HTTP protocol, you must install and 
configure a web server. Apache2 is proven to work with Subversion. Please 
refer to the HTTP subsection in the Apache2 section to install and configure 
Apache2.  To access the Subversion repository using the HTTPS protocol, you 
must install and configure a digital certificate in your Apache 2 web server. 
Please refer to the HTTPS subsection in the Apache2 section to install and 
configure the digital certificate.
						</p>
<p class="para">
		To install Subversion, run the following command from a terminal prompt:
            </p>
<p class="para">
<div class="screen"><pre class="contents "><span class="cmd command">sudo apt install subversion apache2 libapache2-svn</span>
</pre></div>
	    </p>
</div></div>
</div></div>
<div class="sect2 sect" id="subversion-configuration"><div class="inner">
<div class="hgroup"><h2 class="title">Server Configuration</h2></div>
<div class="region">
<div class="contents"><p class="para">
	This step assumes you have installed above mentioned packages on your system. This section explains how to create a Subversion repository and access the project.</p></div>
<div class="sect3 sect" id="create-svn-repos"><div class="inner">
<div class="hgroup"><h3 class="title">Create Subversion Repository</h3></div>
<div class="region"><div class="contents">
<p class="para">The Subversion repository can be created using the following command from a terminal prompt:</p>
<p class="para">
<div class="screen"><pre class="contents "><span class="cmd command">svnadmin create /path/to/repos/project</span>
</pre></div>
        </p>
</div></div>
</div></div>
<div class="sect3 sect" id="import-svn-files"><div class="inner">
<div class="hgroup"><h3 class="title">Importing Files</h3></div>
<div class="region"><div class="contents"><p class="para">
                            Once you create the repository you can
                            <span class="em emphasis">import</span> files into the
                            repository.  To import a directory, enter the
                            following from a terminal prompt:
<div class="screen"><pre class="contents "><span class="cmd command">svn import /path/to/import/directory file:///path/to/repos/project</span>
</pre></div>
                            </p></div></div>
</div></div>
</div>
</div></div>
<div class="sect2 sect" id="access-methods"><div class="inner">
<div class="hgroup"><h2 class="title">Access Methods</h2></div>
<div class="region">
<div class="contents">
<p class="para">Subversion repositories can be accessed (checked out) through many 
different methods --on local disk, or through various network protocols. 
A repository location, however, is always a URL. The table describes how 
different URL schemes map to the available access methods.</p>
<div class="table">
<div class="title"><h3><span class="title">Access Methods</span></h3></div>
<table summary="Access Methods" style="border: solid 1px;">
<thead><tr>
<th class="td-colsep"><p class="para">Schema</p></th>
<th><p class="para">Access Method</p></th>
</tr></thead>
<tbody>
<tr>
<td class="td-colsep"><p class="para">file://</p></td>
<td><p class="para">direct repository access (on local disk)</p></td>
</tr>
<tr class="shade">
<td class="td-colsep"><p class="para">http://</p></td>
<td><p class="para">Access via WebDAV protocol to Subversion-aware Apache2 web server</p></td>
</tr>
<tr>
<td class="td-colsep"><p class="para">https://</p></td>
<td><p class="para">Same as http://, but with SSL encryption</p></td>
</tr>
<tr class="shade">
<td class="td-colsep"><p class="para">svn://</p></td>
<td><p class="para">Access via custom protocol to an svnserve server</p></td>
</tr>
<tr>
<td class="td-colsep"><p class="para">svn+ssh://</p></td>
<td><p class="para">Same as svn://, but through an SSH tunnel</p></td>
</tr>
</tbody>
</table>
</div>
<p class="para">
In this section, we will see how to configure Subversion for all 
these access methods. Here, we cover the basics. For more advanced 
usage details, refer to the <a href="http://svnbook.red-bean.com/" class="ulink" title="http://svnbook.red-bean.com/">svn book</a>.
				</p>
</div>
<div class="sect3 sect" id="direct-repos-access"><div class="inner">
<div class="hgroup"><h3 class="title">Direct repository access (file://)</h3></div>
<div class="region"><div class="contents">
<p class="para"> This is the simplest of all access methods. It does not 
require any Subversion server process to be running. This access 
method is used to access Subversion from the same machine. The 
syntax of the command, entered at a terminal prompt, is as follows:</p>
<p class="para">
<div class="screen"><pre class="contents "><span class="cmd command">svn co file:///path/to/repos/project</span>
</pre></div>
        </p>
<p class="para">or</p>
<p class="para">
<div class="screen"><pre class="contents "><span class="cmd command">svn co file://localhost/path/to/repos/project</span>
</pre></div>
        </p>
<div class="note" title="Note"><div class="inner"><div class="region"><div class="contents">
		<p class="para">If you do not specify the hostname, there are three forward slashes (///) -- two for the protocol (file, in this case) plus the leading slash in the path. If you specify the hostname, you must use two forward slashes (//).</p>
	</div></div></div></div>
<p class="para">The repository permissions depend on filesystem permissions. If the user has read/write permission, he can checkout from and commit to the repository.</p>
</div></div>
</div></div>
<div class="sect3 sect" id="access-via-webdav"><div class="inner">
<div class="hgroup"><h3 class="title">Access via WebDAV protocol (http://)</h3></div>
<div class="region"><div class="contents">
<p class="para">
                          To access the Subversion repository via WebDAV protocol, you must configure your Apache 2 web server. Add the following snippet between the 
                          <span class="em emphasis">&lt;VirtualHost&gt;</span> and <span class="em emphasis">&lt;/VirtualHost&gt;</span> elements in
                          <span class="file filename">/etc/apache2/sites-available/000-default.conf</span>, or another VirtualHost file:
                          </p>
<div class="code"><pre class="contents "> &lt;Location /svn&gt;
  DAV svn
  SVNParentPath /path/to/repos
  AuthType Basic
  AuthName "Your repository name"
  AuthUserFile /etc/subversion/passwd
  Require valid-user
 &lt;/Location&gt; 
</pre></div>
<div class="note" title="Note"><div class="inner"><div class="region"><div class="contents">
		<p class="para">The above configuration snippet assumes that Subversion
    repositories are created under <span class="file filename">/path/to/repos</span>
    directory using <span class="cmd command">svnadmin</span> command and that the HTTP user has sufficent access rights to the files (see below).  They can be
    accessible using <span class="cmd command">http://hostname/svn/repos_name</span>
    url.</p>
    </div></div></div></div>
<p class="para">
         Changing the apache configuration like the above requires to reload
         the service with the following command
         </p>
<div class="screen"><pre class="contents ">    <span class="cmd command">sudo systemctl reload apache2.service</span>
</pre></div>
<p class="para">
         To import or commit files to your Subversion repository over
         HTTP, the repository should be owned by the HTTP user. In
         Ubuntu systems, the HTTP user is
         <span class="cmd command">www-data</span>.  To change the ownership of the
         repository files enter the following command from terminal
         prompt:
         </p>
<div class="screen"><pre class="contents ">    <span class="cmd command">sudo chown -R www-data:www-data /path/to/repos</span>
</pre></div>
<div class="note" title="Note"><div class="inner"><div class="region"><div class="contents">
        <p class="para">
        By changing the ownership of repository as
        <span class="cmd command">www-data</span> you will not be able to import or
        commit files into the repository by running <span class="cmd command">svn import
        file:///</span> command as any user other than
        <span class="cmd command">www-data</span>.
        </p>
        </div></div></div></div>
<p class="para">
        Next, you must create the <span class="file filename">/etc/subversion/passwd</span> file that will contain user authentication details. 
        To create a file issue the following command at a command prompt (which will create the file and add the first user):
        </p>
<div class="screen"><pre class="contents "><span class="cmd command">sudo htpasswd -c /etc/subversion/passwd user_name</span>
</pre></div>
<p class="para">
        To add additional users omit the <span class="em emphasis">"-c"</span> option as this option replaces the old file. Instead use this form:
        </p>
<div class="screen"><pre class="contents "><span class="cmd command">sudo htpasswd /etc/subversion/passwd user_name</span>
</pre></div>
<p class="para">This command will prompt you to enter the password. Once you enter the password, the user is added. Now, to access the repository you can run the following command:</p>
<div class="screen"><pre class="contents "><span class="cmd command">svn co http://servername/svn</span></pre></div>
<div class="note note-warning" title="Warning"><div class="inner"><div class="region"><div class="contents">
		<p class="para">
			The password is transmitted as plain text. If you are worried about password snooping, you are advised to use SSL encryption. For details, please refer next section.
		</p>
	</div></div></div></div>
</div></div>
</div></div>
<div class="sect3 sect" id="access-via-webdav-with-ssl"><div class="inner">
<div class="hgroup"><h3 class="title">Access via WebDAV protocol with SSL encryption (https://)</h3></div>
<div class="region"><div class="contents">
<p class="para"> 
					Accessing Subversion repository via WebDAV protocol with SSL 
					encryption (https://) is similar to http:// except that you 
					must install and configure the digital certificate in your 
					Apache2 web server.  To use SSL with Subversion add the above
                                        Apache2 configuration to <span class="file filename">/etc/apache2/sites-available/default-ssl.conf</span>.
                                        For more information on setting up Apache2 with SSL see <a class="xref" href="httpd.html#https-configuration" title="HTTPS Configuration">HTTPS Configuration</a>.
					</p>
<p class="para">
						You can install a digital certificate issued by a signing 
						authority. Alternatively, you can install your 
						own self-signed certificate.
					</p>
<p class="para">
						This step assumes you have installed and configured a digital 
						certificate in your Apache 2 web server. Now, to access the 
						Subversion repository, please refer to the above section! 
						The access methods are exactly the same, except the protocol. 
						You must use https:// to access the Subversion repository.
					</p>
</div></div>
</div></div>
<div class="sect3 sect" id="access-via-custom-protocol"><div class="inner">
<div class="hgroup"><h3 class="title">Access via custom protocol (svn://)</h3></div>
<div class="region"><div class="contents">
<p class="para"> 
					Once the Subversion repository is created, you can configure the 
					access control. You can edit the <span class="file filename">
					/path/to/repos/project/conf/svnserve.conf</span> file to 
					configure the access control.  For example, to set up 
					authentication, you can uncomment the following lines in the 
					configuration file: </p>
<div class="code"><pre class="contents "># [general]
# password-db = passwd</pre></div>
<p class="para">
					After uncommenting the above lines, you can maintain the user 
					list in the passwd file. So, edit the file <span class="file filename">passwd
					</span> in the same directory and add the new user. The 
					syntax is as follows:
					</p>
<div class="code"><pre class="contents ">username = password</pre></div>
<p class="para">
					For more details, please refer to the file.
					</p>
<p class="para">
					Now, to access Subversion via the svn:// custom protocol, either 
					from the same machine or a different machine, you can run 
					svnserver using svnserve command. The syntax is as follows:
					</p>
<div class="code"><pre class="contents ">$ svnserve -d --foreground -r /path/to/repos
# -d -- daemon mode
# --foreground -- run in foreground (useful for debugging)
# -r -- root of directory to serve

For more usage details, please refer to:
$ svnserve --help</pre></div>
<p class="para">Once you run this command, Subversion starts listening on default port (3690). To access the project repository, you must run the following command from a terminal prompt: </p>
<p class="para">
<div class="screen"><pre class="contents "><span class="cmd command">svn co svn://hostname/project project --username user_name</span>
</pre></div>
                                        </p>
<p class="para">Based on server configuration, it prompts for password. Once 
					you are authenticated, it checks out the code from Subversion 
					repository.  To synchronize the project repository with the local 
					copy, you can run the <span class="cmd command">update</span> sub-command. The 
					syntax of the command, entered at a terminal prompt, is as follows:
					</p>
<p class="para">
<div class="screen"><pre class="contents "><span class="cmd command">cd project_dir ; svn update</span>
</pre></div>
                                        </p>
<p class="para">For more details about using each Subversion sub-command, you 
					can refer to the manual. For example, to learn more about the co 
					(checkout) command, please run the following command from a 
					terminal prompt:</p>
<p class="para"><div class="screen"><pre class="contents "><span class="cmd command">svn co help</span></pre></div></p>
</div></div>
</div></div>
<div class="sect3 sect" id="access-via-custom-protocol-with-ssh"><div class="inner">
<div class="hgroup"><h3 class="title">Access via custom protocol with SSH encryption (svn+ssh://)</h3></div>
<div class="region"><div class="contents">
<p class="para"> The configuration and server process is same as in the
					svn:// method. For details, please refer to the above section. 
					This step assumes you have followed the above step and started 
					the	Subversion server using <span class="app application">svnserve</span>  
					command.</p>
<p class="para">It is also assumed that the ssh server is running on that 
					machine and that it is allowing incoming connections. To confirm, 
					please try to login to that machine using ssh. If you can login, 
					everything is perfect. If you cannot login, please address it 
					before continuing further.</p>
<p class="para">The svn+ssh:// protocol is used to access the Subversion 
					repository using SSL encryption. The data transfer is encrypted 
					using this method. To access the project repository (for example 
					with a checkout), you must use the following command syntax: 
                                        </p>
<p class="para">
<div class="screen"><pre class="contents ">    <span class="cmd command">svn co svn+ssh://ssh_username@hostname/path/to/repos/project</span>
</pre></div>
                                        </p>
<div class="note" title="Note"><div class="inner"><div class="region"><div class="contents"><p class="para"> You must use the full path (/path/to/repos/project) 
					to access the Subversion repository using this access method. 
					</p></div></div></div></div>
<p class="para">
					Based on server configuration, it prompts for password. You must 
					enter the password you use to login via ssh. Once you are 
					authenticated, it checks out the code from the Subversion 
					repository.
					</p>
</div></div>
</div></div>
</div>
</div></div>
</div>
<div class="links nextlinks">
<a class="nextlinks-prev" href="git.html" title="Git">Previous</a><a class="nextlinks-next" href="version-control-ref.html" title="References">Next</a>
</div>
<div class="clear"></div>
</div>
<div id="pagebottom"></div>
</div></div>
</div>
<div id="footer"><p>The material in this document is available under a free license, see <a href="https://help.ubuntu.com/legal.html">Legal</a> for details.<br>
          For information on contributing see the <a href="https://wiki.ubuntu.com/DocumentationTeam">Ubuntu Documentation Team wiki page</a>.
          To report errors in this serverguide documentation, <a href="https://bugs.launchpad.net/serverguide">file a bug report</a>.</p></div>
</div>
</body>
</html>
